package cn.kgc.controller;


import cn.kgc.dtos.Dto;
import cn.kgc.pojo.ItripUser;
import cn.kgc.service.ItripUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.mobile.device.Device;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/api")
@Api(value = "这是用户模块类",tags = {"dw"})
public class userContrller {

    @Resource
    private ItripUserService itripUserService;

    /**
     * 手机注册方法
     */
    @RequestMapping(value = "/registerbyphone",method = RequestMethod.POST)
    @ApiOperation(value = "注册",httpMethod ="GET",protocols = "http",notes = "注册" )
    public Dto registerbyphone(@RequestBody ItripUser itripUser){
        return itripUserService.register(itripUser);
    }


    /**
     * 邮箱注册方法
     * @param itripUser
     * @return
     */
    @RequestMapping(value = "/doregister",method = RequestMethod.POST)
    public  Dto register(@RequestBody ItripUser itripUser){
        return itripUserService.register(itripUser);
    }

    /**
     * 邮箱激活方法
     * @param user
     * @param code
     * @return
     */
    @RequestMapping(value = "/activate",method = RequestMethod.PUT)
    public  Dto activate(String user,String code){
        return itripUserService.activationuser(user,code);
    }

    /**
     * 用户名验证
     * @param name
     * @return
     */
    @RequestMapping(value = "/ckusr",method = RequestMethod.GET)
    public  Dto ckuser(String name){
       return  itripUserService.ajaxcode(name);
    }

    /**
     * 手机激活方法
     * @param user
     * @param code
     * @return
     */
    @RequestMapping(value = "/validatephone",method = RequestMethod.PUT)
    public Dto validatephone(String user,String code){
        return  itripUserService.activationuser(user,code);
    }

    /**
     * 登陆方法
     * @param name
     * @param password
     * @return
     */
    @RequestMapping(value = "/dologin",method = RequestMethod.POST)
    public  Dto dologin( String name, String password, Device device){
        return  itripUserService.login(name,password,device.getDevicePlatform().name());
    }

    /**
     * 注销方法
     * @param
     * @return
     */
    @RequestMapping(value = "/logout",method = RequestMethod.GET)
    public  Dto logout(HttpServletRequest request){ return itripUserService.logout(request.getHeader("token")); }

    /**
     * 置换token
     * @param
     * @return
     */
    @RequestMapping("/retoken")
    public  Dto retoken(HttpServletRequest request){
        String token= request.getHeader("token");

        return  itripUserService.substitution(token);
    }
}
